<template>
  <router-view></router-view>
</template>

<script setup>
import { ref } from "vue";
import { useStore } from "vuex";
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const store = useStore();
const init = () => {
  const token = localStorage.getItem("token");
  if (!token) return;
  let strings = token.split("."); //截取token，获取载体
  var userinfo = JSON.parse(
    decodeURIComponent(
      escape(window.atob(strings[1].replace(/-/g, "+").replace(/_/g, "/")))
    )
  ); //解析，需要吧‘_’,'-'进行转换否则会无法解析
  const { roleId } = JSON.parse(userinfo.sub);
  if (roleId) {
    store.commit("changeUserPermissions", "admin");
    router.push("/admin/user-management");
  } else {
    store.commit("changeUserPermissions", "user");
  }
};
init();
</script>
<style scoped>
.header {
  background: #4995d7 !important;
}
.el-main {
  padding: 0;
}
</style>